package com.labraff.todo;

import android.app.Application;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class globalApplication extends Application {

    private List<task> taskList = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
        // 数据载入
        taskList.add(new task("做一个APP", false, "细节", "标签1"));
        taskList.add(new task("紧急的",true,"细节","标签2"));
        taskList.add(new task("紧急的，已完成",true,"细节","标签2"));
        taskList.add(new task("非紧急，已完成",false,"细节","标签2"));

        taskList.get(2).setIsDone(true);
        taskList.get(3).setIsDone(true);

//        taskList.add(new task("做一个APP吧", false, "细节", "标签1"));
//
//        taskList.add(new task("做一个APP吧", false, "细节", "标签1"));
//        taskList.add(new task("做一个APP吧", false, "细节", "标签1"));
//        taskList.add(new task("做一个APP吧", false, "细节", "标签1"));
    }

    public List<task> getTaskList(){
        return this.taskList;
    }

    public void addTask(task taskItem){
        this.taskList.add(taskItem);
        Toast.makeText(this,"添加任务成功",Toast.LENGTH_SHORT).show();
    }

    int findTaskIndexById(long id){
        int index = 0;
        for(task item : this.taskList){
            if(id == item.getId()){
                index = this.taskList.indexOf(item);
            }
        }
        return index;
    }

    public void editTask(long TaskId,int editItemCode,List editValue){


        // TODO 从这里开始写
        this.taskList.get(findTaskIndexById(TaskId)).setIsDone(true);
    }



    public List<task> getUndoTaskList() {
        List<task> undoList = new ArrayList<>();
        List<task> totalList = this.taskList;
        for (task item : totalList) {
            if (!item.getIsDone()) {
                undoList.add(item);
            }
        }
        return undoList;
    }

    public List<task> getDoneTaskList() {
        List<task> doneList = new ArrayList<>();
        List<task> totalList = this.taskList;
        for (task item : totalList) {
            if (item.getIsDone()) {
                doneList.add(item);
            }
        }
        return doneList;
    }

    public List<task> getUrgentTaskList() {
        List<task> urgentList = new ArrayList<>();
        List<task> totalList = this.taskList;
        for (task item : totalList) {
            if (item.getIsUrgent()) {
                urgentList.add(item);
            }
        }
        return urgentList;
    }


}
